﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JaxDug.Core.Utilities
{
    public class ConsoleUtil
    {
        public const ConsoleColor Text = ConsoleColor.White;
        public const ConsoleColor Note = ConsoleColor.DarkYellow;
        public const ConsoleColor Default = ConsoleColor.DarkYellow;
        public const ConsoleColor Header = ConsoleColor.Yellow;
        public const ConsoleColor Title = ConsoleColor.Yellow;
        public const ConsoleColor Error = ConsoleColor.Red;
        public const ConsoleColor Typed = ConsoleColor.Cyan;
        public const ConsoleColor Value = ConsoleColor.Green;

        public virtual void RunTestSelector()
        {
        }

        public static void WriteLine(string text = "", ConsoleColor color = Text)
        {
            Console.ForegroundColor = color;
            Console.WriteLine(text);
        }

        public static void Write(string text = "", ConsoleColor color = Text)
        {
            Console.ForegroundColor = color;
            Console.Write(text);
        }

        public static void WriteValue(string name, string value, ConsoleColor namecolor = Text, ConsoleColor valuecolor = Value)
        {
            Write(name, namecolor);
            WriteLine(value, valuecolor);
        }

        public static string Input(string text, string @default = "", ConsoleColor questioncolor = Text, ConsoleColor answercolor = Typed)
        {
            Write(text + " ", questioncolor);
            Console.ForegroundColor = answercolor;
            var input = Console.ReadLine();
            Console.ForegroundColor = ConsoleColor.White;

            if (string.IsNullOrWhiteSpace(input))
            {
                WriteLine("[" + @default + "]", Note);
            }

            return string.IsNullOrWhiteSpace(input) ? @default : input;
        }

        public static bool Confirm(string text, ConsoleColor questioncolor = Text, ConsoleColor answercolor = Typed)
        {
            var input = Input(text + " (Y/N)", "n", questioncolor, answercolor);
            return !string.IsNullOrWhiteSpace(input) && input.ToLower() == "y";
        }
    }
}